<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @classname Category_model
 *
 * @package	Package Name
 * @subpackage	Subpackage
 * @category	Category
 * @author	!Man 
 * @email 	mention@gmail.com
 * @link	http://oemahcode.com
 * created  
 */

class Category_model extends OC_Model {

	function get_all($params = array())
	{
		$this->db->select('SQL_CALC_FOUND_ROWS *', FALSE);
		$this->db->from('category_recipes');

		if (isset($params['sort'], $params['order']))
			$this->db->order_by($params['sort'], $params['order']);

		if (isset($params['page'], $params['rows']))
			$this->db->limit($params['rows'], (intval($params['page']-1)*intval($params['rows'])));

		if (isset($params['query']) && $params['query'] != '')
		{
			$query = $params['query'];
			$likes = array_map(
				function($f) use($query) { return "$f LIKE '%$query%' "; },
				array('cr_name')
			);
			$this->db->where('('.implode(' OR ', $likes).')');
		}

		return $this->fetch_rows();
	}

	function add($data)
	{
		return $this->db->insert('category_recipes', $data);
	}

	function edit($data, $keys)
	{
		return $this->db->update('category_recipes', $data, $keys);
	}

	function delete($keys)
	{
		return $this->db->delete('category_recipes', $keys);
	}

}

/* End of file category_model.php */
/* Location: ./applications/module_admin/recipes/models/category_model.php */